<?php
	if (!class_exists('ctl_order'))
	{
		require_once(CORE_DIR.'/admin/controller/order/ctl.order.php');
	}
	class collocate_goods_admin_cct_order extends ctl_order
	{
		function collocate_goods_admin_cct_order()
		{
			parent::ctl_order();
		}

		function detail()
		{			
			parent::detail();
		}

		function _detail()
		{
			return array(
				'detail_info'=>array('label'=>__('基本信息'),'tpl'=>dirname(__FILE__).'/view/admin/order/order_detail.html'),
				'detail_items'=>array('label'=>__('商品'),'tpl'=>dirname(__FILE__).'/view/admin/order/od_items.html'),
				'detail_bills'=>array('label'=>__('收退款记录'),'tpl'=>'order/od_bill.html'),
				'detail_delivery'=>array('label'=>__('收发货记录'),'tpl'=>'order/od_delivery.html'),
				'detail_pmt'=>array('label'=>__('优惠方案'),'tpl'=>'order/od_pmts.html'),
				'detail_mark'=>array('label'=>__('订单备注'),'tpl'=>'order/od_mark.html'),
				'detail_logs'=>array('label'=>__('订单日志'),'tpl'=>'order/od_logs.html'),
				'detail_msg'=>array('label'=>__('顾客留言'),'tpl'=>'order/od_msg.html'),
				);
		}

		function detail_info($order_id)
		{
			;
		}

		function detail_items($order_id)
		{
			;
		}

		function toEdit()
		{
			error_log(print_r($_POST,true),3,__FILE__.'.'.__FUNCTION__.'._POST.log');//alone add
			//是否有搭配商品
			if ($_POST['hasColloc'])
			{
				if (count($_POST['aItems']))
				{
					$objCollocOrder = $this->system->loadModel('plugins/collocate_goods/collocOrder');
					if (!$objCollocOrder->editOrder($_POST))
					{
						trigger_error(__('搭配商品库存不足'),E_USER_ERROR);
					}
				}
				//else trigger_error(__('没有搭配商品商品明细'),E_USER_ERROR);
			}
			parent::toEdit();
		}

		function showEdit($orderid)
		{
			$this->path[] = array('text'=>__('订单编辑'));
			$objOrder = &$this->system->loadModel('trading/order');
			$aOrder = $objOrder->getFieldById($orderid);
			$aOrder['discount'] = 0 - $aOrder['discount'];

			$oCur = &$this->system->loadModel('system/cur');
			$aCur = $oCur->getSysCur();
			$aOrder['cur_name'] = $aCur[$aOrder['currency']];

			$aOrder['items'] = $objOrder->getItemList($orderid);
			$aOrder['pmt'] = $objOrder->getPmtList($orderid);

			if($aOrder['member_id'] > 0){
				$objMember = &$this->system->loadModel('member/member');
				$aOrder['member'] = $objMember->getFieldById($aOrder['member_id'], array('*'));
				$aOrder['ship_email'] = $aOrder['member']['email'];
			}else{
				$aOrder['member'] = array();
			}

			$objDelivery = &$this->system->loadModel('trading/delivery');
			$aArea = $objDelivery->getDlAreaList();
			foreach ($aArea as $v){
				$aTmp[$v['name']] = $v['name'];
			}
			$aOrder['deliveryArea'] = $aTmp;

			$aRet = $objDelivery->getDlTypeList();
			foreach ($aRet as $v){
				$aShipping[$v['dt_id']] = $v['dt_name'];
			}
			$aOrder['selectDelivery'] = $aShipping;

			$objPayment = &$this->system->loadModel('trading/payment');
			$aRet = $objPayment->getMethods();
			$aPayment[-1] = '货到付款';
			foreach ($aRet as $v){
				$aPayment[$v['id']] = $v['custom_name'];
			}
			$aOrder['extendCon'] = $objPayment->getExtendCon($aOrder['extend'],$aOrder['payment']);
			$aOrder['selectPayment'] = $aPayment;

			$objCurrency = &$this->system->loadModel('system/cur');
			$aRet = $objCurrency->curAll();
			foreach ($aRet as $v){
				$aCurrency[$v['cur_code']] = $v['cur_name'];
			}
			$aOrder['curList'] = $aCurrency;
			$this->pagedata['order'] = $aOrder;
			$this->pagedata['edit_items_path'] = dirname(__FILE__).'/view/admin/order/edit_items.html';
			$this->pagedata['order_edit_path'] = dirname(__FILE__).'/view/admin/order/order_edit.html';
			$this->pagedata['edit_po_path'] = dirname(__FILE__).'/view/admin/order/edit_po.html';
			$this->pagedata['order_new_path'] = dirname(__FILE__).'/view/admin/order/order_new.html';
			$this->singlepage(dirname(__FILE__).'/view/admin/order/page.html');
		}
	}

?>